export function sleep (waitTime = 500) {
    // 异步函数的强制等待
    return new Promise(resolve => {
        setTimeout(resolve, waitTime);
    });
}

export async function toBeRun (func, num, waitTime) {
    // 同步函数强制间隔时间再执行
    let result = [];
    for (let i = 0; i < num; i++) {
        result.push(func());
        await sleep(waitTime);
    }
    return result;
}

export async function toBeRunUp (func, queue, waitTime) {
    // 异步函数强制间隔时间执行，并返回句柄
    let result = [];
    const keys = Object.keys(queue);
    for (const key of keys) {
        const item = queue[key];
        result.push(func(item, key, queue));
        await sleep(waitTime);
    }
    return result;
}
